/*
 *  ComposerVP.cpp
 *  openFrameworks
 *
 *  Created by fregment on 08.06.09.
 *  Copyright 2009 __MyCompanyName__. All rights reserved.
 *
 */

#include "ComposerVP.h"


namespace abliefern {
	
	
	ComposerVP::ComposerVP(int theX, int theY, int theR,int theGridSize,int theGridDistance ){
	
		x=theX;
		y=theY;
		r=theR;
		gridSize = theGridSize;
		gridDist = theGridDistance;

		
		isActive=false;
		
		
		
		

	}
	
	
		
	
	void ComposerVP::shiftPoints(int theX, int theY){
		
		Point2f	myNewPoint;
		myNewPoint.x=theX-x;
		myNewPoint.y=theY-y;
		
		
		
		for (int i=0; i<gridPoints.size(); i++){
			
			gridPoints.at(i).subtract(myNewPoint.x,myNewPoint.y);
			
		
		
		}
		
		
	
	
	}
	
	
	void ComposerVP::deleteGrid(){
		gridPoints.clear();
	
	}
	
	void ComposerVP::drawGrid(){
		
		if(isActive==false){
		ofSetColor(50,50,100);
		}else{
		ofSetColor(0,200,0);
		}
		
		
		for (int i=0; i<gridPoints.size(); i++){
			ofCircle(gridPoints.at(i).x+x,  gridPoints.at(i).y+y, 1);
		}
	
	
	}
	
	
	
	bool ComposerVP::isOver(int theX, int theY){
		
		int _dist;
		Segment mySegment(x,y,theX,theY);
		_dist=mySegment.magnitude();
		
		if(_dist < r){
			return true;
		}
		
		return false;
		
	
	}
	
	
	
	
	
	
	
	
	void ComposerVP::addGridPoint(int theX, int theY){
		
		Point2f	myPoint;
		myPoint.x=theX-x;
		myPoint.y=theY-y;		
		gridPoints.push_back(myPoint);
	
	}
	

	
	
	
	
	
	
	void ComposerVP::makeGrid(int theSize, int theDist){
			
		float myOffset = ((theSize/4*theDist)/2)-theDist/2;
		
		for (int i=0; i<theSize/4; i++) {
			for (int j=0; j<theSize/4; j++) {
			
				
				Point2f	myPoint;
				myPoint.x=-myOffset*2.0 *ofRandomuf()+(i*theDist)*2.0* ofRandomuf();
				myPoint.y=-myOffset* ofRandomuf()+(j*theDist)* ofRandomuf() ;
				
				gridPoints.push_back(myPoint);
			
			
			}
	
	}
	}
	
}